#include "endwindow.h"

#include "ui_endwindow.h"

endwindow::endwindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::endwindow) {
  ui->setupUi(this);

  QScreen *scr = QApplication::primaryScreen();
  int scr_w = scr->size().width();
  int scr_h = scr->size().height();
  move((scr_w - this->width()) / 2, (scr_h - this->height()) / 2);

  QGraphicsOpacityEffect *m_pGraphicsOpacityEffect =
      new QGraphicsOpacityEffect(ui->label);
  QGraphicsOpacityEffect *n_pGraphicsOpacityEffect =
      new QGraphicsOpacityEffect(ui->pushButton);
  n_pGraphicsOpacityEffect->setOpacity(1);
  ui->pushButton->setGraphicsEffect(n_pGraphicsOpacityEffect);

  m_pGraphicsOpacityEffect = new QGraphicsOpacityEffect(ui->label);
  m_pGraphicsOpacityEffect->setOpacity(1);
  ui->label->setGraphicsEffect(m_pGraphicsOpacityEffect);
  QPropertyAnimation *m_pNameAnimation;

  m_pNameAnimation =
      new QPropertyAnimation(m_pGraphicsOpacityEffect, "opacity", this);
  QPropertyAnimation *n_pNameAnimation;

  n_pNameAnimation =
      new QPropertyAnimation(n_pGraphicsOpacityEffect, "opacity", this);
  n_pNameAnimation->setEasingCurve(QEasingCurve::Linear);
  n_pNameAnimation->setDuration(5000);

  n_pNameAnimation->setStartValue(0);
  n_pNameAnimation->setEndValue(1);
  m_pNameAnimation->setEasingCurve(QEasingCurve::Linear);
  m_pNameAnimation->setDuration(5000);

  m_pNameAnimation->setStartValue(0);
  m_pNameAnimation->setEndValue(1);
  m_pNameAnimation->start(QAbstractAnimation::KeepWhenStopped);
  n_pNameAnimation->start(QAbstractAnimation::KeepWhenStopped);
  this->setAttribute(Qt::WA_TranslucentBackground);
}

endwindow::~endwindow() { delete ui; }

void endwindow::on_pushButton_clicked() {
  startWindow *sta = new startWindow;
  sta->show();
  this->close();
}
